home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / workbench / processicon / source / processicon.c
C/C++ Source or Header  |  1999-11-30  |  27KB  |  709 lines

  1. #define NAME     "ProcessIcon"
  2. #define REVISION "16"
  3.  
  4. /* Programmheader
  5.  
  6.         Name:           ProcessIcon
  7.         Author:         SDI
  8.         Distribution:   PD
  9.         Description:    processes .info files
  10.         Compileropts:   -
  11.         Linkeropts:     -l amiga
  12.  
  13.  1.0   01.93.97 : first version
  14.  1.1   03.03.97 : options KILLSTACKSIZE, KILLDEFTOOL, VIEW
  15.  1.2   05.03.97 : added SIT and CIT options
  16.  1.3   29.03.97 : not existing TO produces icon
  17.  1.4   13.06.97 : lots of changes, renamed from CopyIconImage
  18.  1.5   14.06.97 : added more data to VIEW option
  19.  1.6   01.07.97 : fixed problem with DrawerData
  20.  1.7   09.11.97 : added UNSNAP function
  21.  1.8   05.02.98 : IMGSRC became REFICON, added CII instead of autocopy
  22.  1.9   01.09.98 : better VIEW output
  23.  1.10  08.05.99 : added REMAP option
  24.  1.11  21.09.99 : KTT removes entry totally
  25.  1.12  11.10.99 : add SSS option
  26.  1.13  05.11.99 : added NewIcon support
  27.  1.14  09.11.99 : added OS3.5 support, better source, removed global variables,
  28.     program got multi-reentrant
  29.  1.15  10.11.99 : little bug fix
  30.  1.16  15.11.99 : added MAKECI
  31. */
  32.  
  33. #include <proto/dos.h>
  34. #include <proto/icon.h>
  35. #include <proto/exec.h>
  36. #include <proto/graphics.h>
  37. #include <exec/memory.h>
  38. #include <workbench/icon.h>
  39. #define SDI_TO_ANSI
  40. #include "SDI_ASM_STD_protos.h"
  41. #include "SDI_defines.h"
  42.  
  43. #define PARAM (STRPTR)  "ICON/A,REFICON,VIEW/S,OPT=OPTIMIZE/S,"         \
  44.                         "US=UNSNAP/S,REMAP/S,"                          \
  45.                         "NI2CI/S,MWB2CI/S,II2CI/S,MAKECI/S,"            \
  46.                         "SBP=SETBITPLANES/N,SDT=SETDEFTOOL,"            \
  47.                         "SIT=SETICONTYPE,SSS=SETSTACKSIZE/N,"           \
  48.                         "ST1=SETTRANSPARENT1/N,ST2=SETTRANSPARENT2/N,"    \
  49.                         "SXP=SETXPOS/N,SYP=SETYPOS/N,"                  \
  50.                         "KCI=KILLCOLORICON/S,"                          \
  51.                         "KDD=KILLDRAWERDATA/S,KDT=KILLDEFTOOL/S,"       \
  52.                         "KII=KILLICONIMAGE/S,KNI=KILLNEWICON/S,"        \
  53.                         "KSS=KILLSTACKSIZE/S,KTT=KILLTOOLTYPES/S,"      \
  54.                         "CCI=COPYCOLORICON/S,"                          \
  55.                         "CDD=COPYDRAWERDATA/S,CDT=COPYDEFTOOL/S,"       \
  56.                         "CII=COPYICONIMAGE/S,CIT=COPYICONTYPE/S,"       \
  57.                         "CNI=COPYNEWICON/S,CSS=COPYSTACKSIZE/S,"        \
  58.                         "CTT=COPYTOOLTYPES/S"
  59. struct Args {
  60.     STRPTR      icon;
  61.     STRPTR      reficon;
  62.     ULONG       view;
  63.     ULONG       optimize;
  64.     ULONG       unsnap;
  65.     ULONG       remap;
  66.     ULONG       ni2ci;
  67.     ULONG       mwb2ci;
  68.     ULONG       ii2ci;
  69.     ULONG       makeci;
  70.     ULONG *     setbitplanes;
  71.     STRPTR      setdeftool;
  72.     STRPTR      seticontype;
  73.     ULONG *     setstacksize;
  74.     LONG *    settransparent1;
  75.     LONG *      settransparent2;
  76.     ULONG *     setxpos;
  77.     ULONG *     setypos;
  78.     ULONG       killcoloricon;
  79.     ULONG       killdrawerdata;
  80.     ULONG       killdeftool;
  81.     ULONG       killiconimage;
  82.     ULONG       killnewicon;
  83.     ULONG       killstacksize;
  84.     ULONG       killtooltypes;
  85.     ULONG       copycoloricon;
  86.     ULONG       copydrawerdata;
  87.     ULONG       copydeftool;
  88.     ULONG       copyiconimage;
  89.     ULONG       copyicontype;
  90.     ULONG       copynewicon;
  91.     ULONG       copystacksize;
  92.     ULONG       copytooltypes;
  93. };
  94.  
  95. const STRPTR IconTypeRecog[] = {0, "Disk", "Drawer", "Tool", "Project", "Garbage", "Device", "Kick", "AppIcon"};
  96. const UBYTE NewIconTXT[] = "*** DON'T EDIT THE FOLLOWING LINES!! ***";
  97. const UWORD KIIData[] = {0xF000,0xF000,0xF000,0xF000};
  98. const struct Image KIIImage = {0, 0, 4, 4, 1, (UWORD *) &KIIData, 1, 0, 0};
  99. const UBYTE MagicWBPalette[8 * 3] = { 0x96,0x96,0x96, 0x00,0x00,0x00, 0xFF,0xFF,0xFF, 0x3D,0x65,0xA2,
  100.       0x79,0x79,0x79, 0xAE,0xAE,0xAE, 0xAA,0x92,0x7D, 0xFF,0xAA,0x96};
  101. const UBYTE Default8Palette[8 * 3] = { 0xAA,0xAA,0xAA, 0x00,0x00,0x00, 0xFF,0xFF,0xFF, 0x65,0x8A,0xBA,
  102.       0xEF,0x45,0x45, 0x55,0xDF,0x55, 0x00,0x45,0xDF, 0xEF,0x9A,0x00};
  103.  
  104. static void RemapImage(struct Image *im)
  105. {
  106.   ULONG w, i, j, k, d;
  107.   UWORD *ptr;
  108.  
  109.   w = (im->Width+15)>>4; /* divide by 16 */
  110.   ptr = im->ImageData;
  111.  
  112.   if(im->Depth == 1)
  113.   {
  114.     for(i = 0; i < im->Height; ++i)
  115.     {
  116.       for(j = 0; j < w; ++j)
  117.         ptr[i*w + j] ^= 0xFFFF;
  118.       if((k = (w<<4) - im->Width))
  119.       {
  120.         /* clear last unused bits */
  121.         ptr[i*w + j - 1] &= (0xFFFF >> k) << k;
  122.       }
  123.     }
  124.   }
  125.   else
  126.   {
  127.     for(i = 0; i < im->Height; ++i)
  128.     {
  129.       for(j = 0; j < w; ++j)
  130.       {
  131.         k = ptr[i*w + j] ^ ptr[(im->Height + i)*w + j];
  132.         for(d = 2; d < im->Depth; ++d)
  133.           k &= (~ptr[(im->Height*d +i)*w + j]);
  134.         ptr[i*w + j] ^= k;
  135.         ptr[(im->Height + i)*w + j] ^= k;
  136.       }
  137.       if((k = (w<<4) - im->Width))
  138.       {
  139.         /* clear last unused bits */
  140.         ptr[i*w + j - 1] &= (0xFFFF >> k) << k;
  141.         ptr[(im->Height + i)*w + j - 1] &= (0xFFFF >> k) << k;
  142.       }
  143.     }
  144.   }
  145. }
  146.  
  147. #define TESTGROUP(a, b, c)      if((a && (b || c)) || (b && c)) ++argerr
  148.  
  149. #define TYPE_STANDARD   0
  150. #define TYPE_NEWICON    1
  151. #define TYPE_NEWICON35  2
  152. #define TYPE_OS35       3
  153. #define TYPE_BOTHCOLOR  4
  154.  
  155. ULONG dowork(struct Args *args, struct Library *IconBase, ULONG os35mode)
  156. {
  157.   ULONG ret = RETURN_FAIL, s;
  158.   struct DiskObject *dobj;
  159.  
  160.   if((dobj = (os35mode ? GetIconTags(args->icon,
  161.   ICONGETA_FailIfUnavailable, FALSE, ICONGETA_GetPaletteMappedIcon, FALSE, TAG_DONE) :
  162.   GetDiskObjectNew(args->icon))))
  163.   {
  164.     struct DiskObject *dobjdrw; 
  165.     if((dobjdrw = GetDefDiskObject(WBDRAWER)))
  166.     {
  167.       struct DiskObject *dobjsrc = 0;
  168.  
  169.       if(!args->reficon || (dobjsrc = (os35mode ?
  170.       GetIconTags(args->reficon, 0) : GetDiskObject(args->reficon))))
  171.       {
  172.         STRPTR *tooltypes;
  173.         UBYTE *imageBuffers = 0;
  174.         
  175.         if((tooltypes = (STRPTR *) AllocVec(1000*sizeof(STRPTR), MEMF_CLEAR)))
  176.         {
  177.           ULONG type = TYPE_STANDARD;
  178.           STRPTR *tt, t, t2;
  179.  
  180.           if((tt = (STRPTR *) dobj->do_ToolTypes))
  181.           {
  182.             while(*tt)
  183.             {
  184.               if((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT))
  185.                 type = TYPE_NEWICON;
  186.               ++tt;
  187.             }
  188.           }
  189.  
  190.           if(os35mode)
  191.           {
  192.             LONG p = 0, n = 0;
  193.           
  194.             IconControl(dobj, ICONCTRLA_IsPaletteMapped, &p, ICONCTRLA_IsNewIcon, &n, TAG_DONE);
  195.             if(p) type = TYPE_OS35;
  196.             if(n) type = TYPE_NEWICON35;
  197.             if(p && n) type = TYPE_BOTHCOLOR;
  198.           }
  199.  
  200.       if(args->makeci)
  201.       {
  202.         switch(type)
  203.         {
  204.         case TYPE_STANDARD: args->ii2ci = 1; break;
  205.         case TYPE_NEWICON: case TYPE_NEWICON35: args->ni2ci = 1; /* no break */
  206.         case TYPE_BOTHCOLOR: args->killnewicon = 1; break;
  207.         }
  208.       }
  209.  
  210.           if(args->view)
  211.           {
  212.             switch(type)
  213.             {
  214.               case TYPE_BOTHCOLOR: t = "OS3.5 Icon + NewIcon"; break;
  215.               case TYPE_NEWICON: case TYPE_NEWICON35: t = "NewIcon"; break;
  216.               case TYPE_OS35: t = "OS3.5 Icon"; break;
  217.               default: t = "Standard"; break;
  218.             }
  219.  
  220.             if(type == TYPE_NEWICON)
  221.             {
  222.               t2 = "YES, NEWICON";
  223.  
  224.               if((**dobj->do_ToolTypes == ' ') && *(dobj->do_ToolTypes[1]) &&
  225.               !strcmp(dobj->do_ToolTypes[1], (STRPTR) NewIconTXT))
  226.                 t2 = "YES - EMPTY, NEWICON";
  227.             }
  228.             else if(type == TYPE_NEWICON35 || type == TYPE_BOTHCOLOR)
  229.             {
  230.               t2 = "YES, NEWICON";
  231.  
  232.               if(!(*dobj->do_ToolTypes))
  233.                 t2 = "YES - EMPTY, NEWICON";
  234.             }
  235.             else if(dobj->do_ToolTypes)
  236.             {
  237.               if(!(*dobj->do_ToolTypes))
  238.                 t2 = "YES - EMPTY";
  239.               else
  240.                 t2 = "YES";
  241.             }
  242.             else
  243.               t2 = "NO";
  244.  
  245.             Printf("Name: %s\nType: %s\n  SS: %ld\n  IT: %s\n  BP: %ld,%ld\n  SZ: ",
  246.               args->icon, t, dobj->do_StackSize, IconTypeRecog[dobj->do_Type],
  247.               ((struct Image *)dobj->do_Gadget.GadgetRender)->Depth,
  248.               (dobj->do_Gadget.SelectRender ?
  249.               ((struct Image *)dobj->do_Gadget.SelectRender)->Depth : 0));
  250.             Printf(dobj->do_CurrentX == NO_ICON_POSITION ? "NOPOS" : "x=%3ld",
  251.               dobj->do_CurrentX);
  252.             Printf(dobj->do_CurrentY == NO_ICON_POSITION ? ", NOPOS" : ", y=%3ld",
  253.               dobj->do_CurrentY);
  254.             Printf(", w=%3ld, h=%3ld\n  DT: (%s) %s\n",
  255.               dobj->do_Gadget.Width, dobj->do_Gadget.Height,
  256.               (dobj->do_DefaultTool ? "YES" : "NO"), dobj->do_DefaultTool);
  257.             
  258.             if(type == TYPE_OS35 || type == TYPE_BOTHCOLOR)
  259.             {
  260.           LONG t1 = -1, t2 = -1, fr = 0, w = 0, h = 0, i2, s1, s2;
  261.  
  262.               IconControl(dobj, ICONCTRLA_GetTransparentColor1, &t1, TAG_DONE);
  263.               IconControl(dobj, ICONCTRLA_GetPaletteSize1, &s1, TAG_DONE);
  264.               IconControl(dobj, ICONCTRLA_GetPaletteSize2, &s2, TAG_DONE);
  265.               IconControl(dobj, ICONCTRLA_GetTransparentColor2, &t2, TAG_DONE);
  266.               IconControl(dobj, ICONCTRLA_GetImageData2, &i2, TAG_DONE);
  267.               IconControl(dobj, ICONCTRLA_GetFrameless, &fr, TAG_DONE);
  268.               IconControl(dobj, ICONCTRLA_GetWidth, &w, TAG_DONE);
  269.               IconControl(dobj, ICONCTRLA_GetHeight, &h, TAG_DONE);
  270.  
  271.           Printf("  CI -Width      : %3ld\n  CI -Height     : %3ld\n"
  272.           "  CI -Borderless : %s\n  CI -NumImages  : %3ld\n  CI1-Transparent: ",
  273.           w, h, fr ? "YES" : "NO",i2 ? 2 : 1);
  274.           
  275.           Printf(t1 == -1 ? "NO" : "%3ld", t1);
  276.           Printf("\n  CI1-NumColors  : %3ld\n", s1);
  277.           if(i2)
  278.           {
  279.                 Printf("  CI2-Transparent: ");
  280.             Printf(t2 == -1 ? "NO" : "%3ld", t2);
  281.                 Printf("\n  CI2-NumColors  : %3ld\n", s2);
  282.               }
  283.             }
  284.  
  285.             Printf("  TT: (%s)\n", t2);
  286.  
  287.             if((tt = (STRPTR *) dobj->do_ToolTypes))
  288.             {
  289.               while(*tt)
  290.               {
  291.                 if((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT))
  292.                   break;
  293.                 else
  294.                   Printf("  %s\n", *(tt++));
  295.               }
  296.             }
  297.             ret = RETURN_OK;
  298.  
  299. #ifdef DEBUG
  300.   Printf("NextGadget:   $%08lx\n", dobj->do_Gadget.NextGadget);
  301.   Printf("LeftEdge:     %4ld\n", dobj->do_Gadget.LeftEdge);
  302.   Printf("TopEdge:      %4ld\n", dobj->do_Gadget.TopEdge);
  303.   Printf("Width:        %4ld\n", dobj->do_Gadget.Width);
  304.   Printf("Height:       %4ld\n", dobj->do_Gadget.Height);
  305.   Printf("Flags:        $%04lx\n", dobj->do_Gadget.Flags);
  306.   Printf("Activation:   $%04lx\n", dobj->do_Gadget.Activation);
  307.   Printf("GadgetType:   %4ld\n", dobj->do_Gadget.GadgetType);
  308.   Printf("GadgetRender: $%08lx\n", dobj->do_Gadget.GadgetRender);
  309.   Printf("SelectRender: $%08lx\n", dobj->do_Gadget.SelectRender);
  310.   Printf("GadgetText:   $%08lx\n", dobj->do_Gadget.GadgetText);
  311.   Printf("MutualExclude:%4ld\n", dobj->do_Gadget.MutualExclude);
  312.   Printf("SpecialInfo:  $%08lx\n", dobj->do_Gadget.SpecialInfo);
  313.   Printf("GadgetID:     %4ld\n", dobj->do_Gadget.GadgetID);
  314.   Printf("UserData:     $%08lx\n", dobj->do_Gadget.UserData);
  315.   if(dobj->do_Gadget.Flags & GFLG_GADGIMAGE)
  316.   {
  317.     struct Image *i;
  318.     
  319.     i = (struct Image *) dobj->do_Gadget.GadgetRender;
  320.     Printf("LeftEdge:     %4ld\n", i->LeftEdge);
  321.     Printf("TopEdge:      %4ld\n", i->TopEdge);
  322.     Printf("Width:        %4ld\n", i->Width);
  323.     Printf("Height:       %4ld\n", i->Height);
  324.     Printf("Depth:        %4ld\n", i->Depth);
  325.     Printf("ImageData:    $%08lx\n", i->ImageData);
  326.     Printf("PlanePick:    %2ld\n", i->PlanePick);
  327.     Printf("PlaneOnOff:   %2ld\n", i->PlaneOnOff);
  328.     Printf("NextImage:    $%08lx\n", i->NextImage);
  329.   }
  330. #endif
  331.           }
  332.           else
  333.           {
  334.             if(args->copyiconimage)
  335.             {
  336.               if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY != NO_ICON_POSITION)
  337.               {
  338.                 dobj->do_CurrentX += (dobj->do_Gadget.Width>>1) - (dobjsrc->do_Gadget.Width>>1);
  339.                 dobj->do_CurrentY += dobj->do_Gadget.Height - dobjsrc->do_Gadget.Height;
  340.                 /* 'down middle position' of gadget should be same after image copy */
  341.               }
  342.               dobj->do_Gadget = dobjsrc->do_Gadget;       /* copy gadget structures */
  343.             }
  344.  
  345.             if(args->copytooltypes || args->copynewicon)
  346.             {
  347.               s = 0;
  348.               if((tt = (STRPTR *) (args->copytooltypes ? dobjsrc : dobj)->do_ToolTypes))
  349.               {
  350.                  while(*tt && !((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT)))
  351.                   tooltypes[s++] = *(tt++);
  352.               }
  353.               if((tt = (STRPTR *) (args->copynewicon ? dobjsrc : dobj)->do_ToolTypes))
  354.               {
  355.                 while(*tt && !((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT)))
  356.                   ++tt;
  357.                 while(*tt)
  358.                   tooltypes[s++] = *(tt++);
  359.               }
  360.               dobj->do_ToolTypes = (char **) (s ? tooltypes : 0);
  361.             }
  362.  
  363.             if(args->seticontype)
  364.             {
  365.               s = 0;
  366.  
  367.               while(++s <= WBAPPICON && stricmp(IconTypeRecog[s], args->seticontype))
  368.                 ;
  369.               if(s <= WBAPPICON)
  370.                 dobj->do_Type = s;
  371.  
  372.               if(!(dobj->do_DrawerData && (dobj->do_Type == WBDISK ||
  373.               dobj->do_Type == WBGARBAGE || dobj->do_Type == WBDRAWER)))
  374.                 dobj->do_DrawerData = dobjdrw->do_DrawerData;
  375.             }
  376.  
  377.             if(args->remap)
  378.             {
  379.               RemapImage((struct Image *) dobj->do_Gadget.GadgetRender);
  380.               if(dobj->do_Gadget.SelectRender)
  381.                 RemapImage((struct Image *) dobj->do_Gadget.SelectRender);
  382.             }
  383.  
  384.             if(args->setbitplanes)
  385.             {
  386.               ((struct Image *) dobj->do_Gadget.GadgetRender)->Depth = *args->setbitplanes;
  387.               if(dobj->do_Gadget.SelectRender)
  388.                 ((struct Image *) dobj->do_Gadget.SelectRender)->Depth = *args->setbitplanes;
  389.             }
  390.  
  391.             if(args->copydeftool)         dobj->do_DefaultTool = dobjsrc->do_DefaultTool;
  392.             if(args->copyicontype)        dobj->do_Type = dobjsrc->do_Type;
  393.             if(args->copystacksize)       dobj->do_StackSize = dobjsrc->do_StackSize;
  394.             if(args->copydrawerdata)      dobj->do_DrawerData = dobjsrc->do_DrawerData;
  395.                   if(args->setxpos)             dobj->do_CurrentX = *args->setxpos;
  396.             if(args->setypos)             dobj->do_CurrentY = *args->setypos;
  397.             if(args->setstacksize)        dobj->do_StackSize = *args->setstacksize;
  398.             if(args->setdeftool)          dobj->do_DefaultTool = args->setdeftool;
  399.             if(args->unsnap)              dobj->do_CurrentX = dobj->do_CurrentY = NO_ICON_POSITION;
  400.             if(args->killstacksize)       dobj->do_StackSize = 0;
  401.             if(args->killdeftool)         dobj->do_DefaultTool = 0;
  402.  
  403.             if(args->killdrawerdata)
  404.             {
  405.                     dobj->do_DrawerData = dobjdrw->do_DrawerData;
  406.               if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE && dobj->do_Type != WBDRAWER)
  407.                 dobj->do_DrawerData = 0;
  408.             }
  409.  
  410.             if(args->killnewicon && (tt = (STRPTR *) dobj->do_ToolTypes))
  411.             {
  412.               while(*tt)
  413.               {
  414.                 if((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT))
  415.                   *tt = 0;
  416.                 else
  417.                   ++tt;
  418.               }
  419.             }
  420.  
  421.             if(args->killtooltypes && (tt = (STRPTR *) dobj->do_ToolTypes))
  422.             {
  423.               s = 0;
  424.               while(*tt && !((**tt == ' ') && tt[1] && !strcmp(tt[1], (STRPTR) NewIconTXT)))
  425.                 ++tt;
  426.               while(*tt)
  427.                 tooltypes[s++] = *(tt++);
  428.               dobj->do_ToolTypes = (char **) (s ? tooltypes : 0);
  429.             }
  430.  
  431.             if(args->copycoloricon)
  432.             {
  433.               LONG t1=-1, t2=-1, s1=0, s2=0, fr=0, w=0, h=0, wo = 0, ho = 0;
  434.               struct ColorRegister *c1=0, *c2=0;
  435.               UBYTE *i1=0, *i2=0;
  436.               UBYTE as=0;
  437.  
  438.               IconControl(dobjsrc, ICONCTRLA_GetTransparentColor1, &t1, TAG_DONE);
  439.               IconControl(dobjsrc, ICONCTRLA_GetTransparentColor2, &t2, TAG_DONE);
  440.               IconControl(dobjsrc, ICONCTRLA_GetPalette1, &c1, TAG_DONE);
  441.               IconControl(dobjsrc, ICONCTRLA_GetPalette2, &c2, TAG_DONE);
  442.               IconControl(dobjsrc, ICONCTRLA_GetPaletteSize1, &s1, TAG_DONE);
  443.               IconControl(dobjsrc, ICONCTRLA_GetPaletteSize2, &s2, TAG_DONE);
  444.               IconControl(dobjsrc, ICONCTRLA_GetImageData1, &i1, TAG_DONE);
  445.               IconControl(dobjsrc, ICONCTRLA_GetImageData2, &i2, TAG_DONE);
  446.               IconControl(dobjsrc, ICONCTRLA_GetFrameless, &fr, TAG_DONE);
  447.               IconControl(dobjsrc, ICONCTRLA_GetAspectRatio, &as, TAG_DONE);
  448.               IconControl(dobjsrc, ICONCTRLA_GetWidth, &w, TAG_DONE);
  449.               IconControl(dobjsrc, ICONCTRLA_GetHeight, &h, TAG_DONE);
  450.  
  451.               if(!IconControl(dobj, ICONCTRLA_GetWidth, &wo, TAG_DONE))
  452.                 wo =dobj->do_Gadget.Width;
  453.               if(!IconControl(dobj, ICONCTRLA_GetHeight, &ho, TAG_DONE))
  454.                 ho = dobj->do_Gadget.Height;
  455.               if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY != NO_ICON_POSITION)
  456.               {
  457.                 dobj->do_CurrentX += (wo>>1) - (w>>1);
  458.                 dobj->do_CurrentY += ho - h;
  459.                 /* 'down middle position' of gadget should be same after image copy */
  460.               }
  461.  
  462.               IconControl(dobj, ICONCTRLA_SetAspectRatio, as, TAG_DONE);
  463.               IconControl(dobj, ICONCTRLA_SetWidth, w, TAG_DONE);
  464.               IconControl(dobj, ICONCTRLA_SetHeight, h, TAG_DONE);
  465.               IconControl(dobj, ICONCTRLA_SetPaletteSize1, s1, TAG_DONE);
  466.               IconControl(dobj, ICONCTRLA_SetPaletteSize2, s2, TAG_DONE);
  467.               IconControl(dobj, ICONCTRLA_SetPalette1, c1, TAG_DONE);
  468.               IconControl(dobj, ICONCTRLA_SetPalette2, c2, TAG_DONE);
  469.               IconControl(dobj, ICONCTRLA_SetImageData1, i1, TAG_DONE);
  470.               IconControl(dobj, ICONCTRLA_SetImageData2, i2, TAG_DONE);
  471.               IconControl(dobj, ICONCTRLA_SetFrameless, fr, TAG_DONE);
  472.               IconControl(dobj, ICONCTRLA_SetTransparentColor1, t1, TAG_DONE);
  473.               IconControl(dobj, ICONCTRLA_SetTransparentColor2, t2, TAG_DONE);
  474.               type = TYPE_OS35;
  475.             }
  476.  
  477.             if(args->mwb2ci || args->ii2ci) /* made from code by Olaf Barthel */
  478.             {
  479.               struct Image *image[2];
  480.               struct GfxBase *GfxBase;
  481.  
  482.               image[0] = (struct Image *)dobj->do_Gadget.GadgetRender;
  483.               image[1] = (struct Image *)dobj->do_Gadget.SelectRender;
  484.  
  485.               if(/*image[0]->Depth >= 3 &&*/ (GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 37)))
  486.               {
  487.                 struct RastPort rp;
  488.                 struct BitMap bm;
  489.                 LONG pixelsPerImage;
  490.                 int x,y;
  491.                 UBYTE *p, *imageBuffer[2];
  492.                 LONG i, j;
  493.  
  494.                 pixelsPerImage = (LONG)image[0]->Width * (LONG)image[0]->Height;
  495.                 if(image[0]->Depth > 3)
  496.                   image[0]->Depth = 3;
  497.  
  498.                 if((imageBuffers = AllocVec(2 * pixelsPerImage, MEMF_ANY)))
  499.                 {
  500.                   imageBuffer[0] = imageBuffers;
  501.                   imageBuffer[1] = image[1] ? imageBuffers + pixelsPerImage : 0;
  502.  
  503.                   InitRastPort(&rp);
  504.                   rp.BitMap = &bm;
  505.  
  506.                   for(j = 0; j < 2 && image[j]; ++j)
  507.                   {
  508.                     PLANEPTR plane;
  509.                     LONG pageSize;
  510.  
  511.                     memset(&bm, 0, sizeof(struct BitMap));
  512.                     bm.BytesPerRow = RASSIZE(image[j]->Width,1);
  513.                     bm.Rows        = image[0]->Height;
  514.                     bm.Depth       = image[0]->Depth;
  515.                     pageSize = RASSIZE(image[0]->Width,image[0]->Height);
  516.                     plane = (PLANEPTR)image[j]->ImageData;
  517.  
  518.                     for(i = 0; i < 3; ++i)
  519.                     {
  520.                       bm.Planes[i] = plane;
  521.                       plane += pageSize;
  522.                     }
  523.  
  524.                     p = imageBuffer[j];
  525.                     for(y = 0; y < image[0]->Height ; y++)
  526.                     {
  527.                       for(x = 0; x < image[0]->Width ; x++)
  528.                         (*p++) = ReadPixel(&rp,x,y);
  529.                     }
  530.                   }
  531.  
  532.           p = (UBYTE *) (args->mwb2ci ? MagicWBPalette : Default8Palette);
  533.  
  534.                   IconControl(dobj, ICONCTRLA_SetWidth, image[0]->Width, ICONCTRLA_SetHeight, image[0]->Height,
  535.                   ICONCTRLA_SetAspectRatio, PACK_ICON_ASPECT_RATIO(1,1), ICONCTRLA_SetImageData1, imageBuffer[0],
  536.                   ICONCTRLA_SetPaletteSize1, 1<<(image[0]->Depth), ICONCTRLA_SetPalette1, p, TAG_DONE);
  537.  
  538.                   if(image[1])
  539.                   {
  540.                     IconControl(dobj, ICONCTRLA_SetImageData2, imageBuffer[1], ICONCTRLA_SetPaletteSize2,
  541.                     1<<(image[0]->Depth), ICONCTRLA_SetPalette2, p, TAG_DONE);
  542.                   }
  543.                   type = TYPE_OS35;
  544.                 }
  545.                 CloseLibrary((struct Library *) GfxBase);
  546.               }
  547.             } /* args->mwb2ci */
  548.  
  549.         if(os35mode)
  550.         {
  551.           if(args->settransparent1) IconControl(dobj, ICONCTRLA_SetTransparentColor1, *args->settransparent1, TAG_DONE);
  552.           if(args->settransparent2) IconControl(dobj, ICONCTRLA_SetTransparentColor2, *args->settransparent2, TAG_DONE);
  553.         }
  554.  
  555.             if(args->killiconimage)
  556.             {
  557.               if(dobj->do_CurrentX != NO_ICON_POSITION && dobj->do_CurrentY != NO_ICON_POSITION
  558.               && type == TYPE_STANDARD)
  559.               {
  560.                 dobj->do_CurrentX += (dobj->do_Gadget.Width>>1) - 2;
  561.                 dobj->do_CurrentY += dobj->do_Gadget.Height - 5;
  562.                 /* 'down middle position' of gadget should be same after image replace */
  563.               }
  564.               dobj->do_Gadget.LeftEdge = dobj->do_Gadget.TopEdge = 50;
  565.               dobj->do_Gadget.Width = dobj->do_Gadget.Height = 4;
  566.               dobj->do_Gadget.Flags = GFLG_GADGIMAGE;
  567.               dobj->do_Gadget.GadgetRender = (APTR) &KIIImage;
  568.               dobj->do_Gadget.SelectRender = 0;
  569.             }
  570.  
  571.             if(args->optimize)
  572.             {
  573.               if(dobj->do_Type != WBDISK && dobj->do_Type != WBPROJECT)
  574.                 dobj->do_DefaultTool = 0;
  575.               if(dobj->do_Type != WBPROJECT && dobj->do_Type != WBTOOL)
  576.                 dobj->do_ToolTypes = 0;
  577.               if(dobj->do_Type != WBDISK && dobj->do_Type != WBGARBAGE && dobj->do_Type != WBDRAWER)
  578.                 dobj->do_DrawerData = 0;
  579.               if(dobj->do_ToolTypes && !(*dobj->do_ToolTypes))
  580.                 dobj->do_ToolTypes = 0;
  581.             }
  582.  
  583.             if(os35mode)
  584.             {
  585.               if(PutIconTags(args->icon, dobj, ICONPUTA_NotifyWorkbench, TRUE, ICONPUTA_PreserveOldIconImages,
  586.               FALSE, args->killnewicon ? ICONPUTA_DropNewIconToolTypes : TAG_IGNORE, TRUE, 
  587.               args->killcoloricon ? ICONPUTA_DropChunkyIconImage : TAG_IGNORE, TRUE,
  588.               args->optimize ? ICONPUTA_OptimizeImageSpace : TAG_IGNORE, TRUE,
  589.               args->killiconimage ? ICONPUTA_DropPlanarIconImage :  TAG_IGNORE, TRUE, TAG_DONE))
  590.                 ret = RETURN_OK;
  591.             }
  592.             else if(PutDiskObject(args->icon, dobj))
  593.               ret = RETURN_OK;
  594.           } /* !args->view */
  595.  
  596.           if(imageBuffers)
  597.             FreeVec(imageBuffers);
  598.           FreeVec(tooltypes);
  599.         } /* allocate tooltype temp array */
  600.         if(dobjsrc)
  601.           FreeDiskObject(dobjsrc);
  602.       } /* open reficon */
  603.       FreeDiskObject(dobjdrw);
  604.     } /* open drawer disk object */
  605.     FreeDiskObject(dobj);
  606.   } /* open DiskObject */
  607.   return ret;
  608. }
  609.  
  610. LONG main(void)
  611. {
  612.   struct RDArgs *rda;
  613.   struct Args args;
  614.   struct Args argse;
  615.   LONG ret = RETURN_FAIL, os35;
  616.  
  617.   memset(&args, 0, sizeof(struct Args));
  618.   if((rda = ReadArgs(PARAM, (LONG *) &args, 0)))
  619.   {
  620.     struct Library *IconBase;
  621.     if((IconBase = OpenLibrary("icon.library", 37)))
  622.     {
  623.       ULONG argerr = 0;
  624.  
  625.       TESTGROUP(0,                args.killcoloricon,   args.copycoloricon);
  626.       TESTGROUP(0,                args.killdrawerdata,  args.copydrawerdata);
  627.       TESTGROUP(args.setdeftool,  args.killdeftool,     args.copydeftool);
  628.       TESTGROUP(0,                args.killiconimage,   args.copyiconimage);
  629.       TESTGROUP(args.seticontype, 0,                    args.copyicontype);
  630.       TESTGROUP(0,                args.killnewicon,     args.copynewicon);
  631.       TESTGROUP(args.setstacksize,args.killstacksize,   args.copystacksize);
  632.       TESTGROUP(0,                args.killtooltypes,   args.copytooltypes);
  633.  
  634.       TESTGROUP(args.ni2ci,       args.ii2ci,           args.mwb2ci);
  635.  
  636.       if(args.makeci && (args.ii2ci || args.mwb2ci || args.ni2ci))
  637.         ++argerr;
  638.  
  639.       if(args.unsnap && (args.setxpos || args.setypos))
  640.         ++argerr;
  641.  
  642.       if(IconBase->lib_Version < 44 && (args.ni2ci || args.ii2ci || args.killcoloricon || args.copycoloricon
  643.       || args.mwb2ci))
  644.       {
  645.         Printf("You need icon.library V44 or better for the CI options.\n");
  646.        ++argerr;
  647.       }
  648.  
  649.       if((args.ni2ci || args.mwb2ci || args.ii2ci) && (args.killcoloricon || args.copycoloricon))
  650.         ++argerr;
  651.  
  652.       if(args.killnewicon && args.ni2ci)
  653.         ++argerr;
  654.       
  655.       if(!args.reficon && (args.copydrawerdata || args.copydeftool || args.copyiconimage || args.copyicontype ||
  656.       args.copynewicon || args.copystacksize || args.copytooltypes))
  657.         ++argerr;
  658.  
  659.       if(argerr || (args.setbitplanes && args.killiconimage))
  660.         SetIoErr(ERROR_TOO_MANY_ARGS);
  661.       else
  662.       {
  663.         ULONG s;
  664.  
  665.         s = strlen(args.icon);
  666.         if(!strncmp(args.icon+s-5, ".info",5))
  667.           args.icon[s-5] = 0;
  668.         if(args.reficon)
  669.         {
  670.           s = strlen(args.reficon);
  671.           if(!strncmp(args.reficon+s-5, ".info",5))
  672.           args.reficon[s-5] = 0;
  673.         }
  674.  
  675.         os35 = IconBase->lib_Version >= 44 ? 1 : 0;
  676.         if(!(ret = dowork(&args, IconBase, os35)))
  677.         {
  678.           if(!args.view && os35 && args.copynewicon)
  679.           {
  680.             memset(&argse, 0, sizeof(struct Args));
  681.             argse.icon = args.icon;
  682.             argse.reficon = args.reficon;
  683.             argse.copynewicon = 1;
  684.             ret = dowork(&argse, IconBase, 0);
  685.           }
  686.           if(!args.view && args.ni2ci)
  687.           {
  688.             struct DiskObject *dobj;
  689.  
  690.             if((dobj = GetIconTags(args.icon, TAG_DONE)))
  691.             {
  692.               if(PutIconTags(args.icon, dobj, ICONPUTA_NotifyWorkbench, TRUE,
  693.               ICONPUTA_DropNewIconToolTypes, TRUE, TAG_DONE));
  694.                 ret = RETURN_OK;
  695.               FreeDiskObject(dobj);
  696.             }
  697.           }
  698.         }
  699.       } /* argument checks */
  700.       CloseLibrary(IconBase);
  701.     } /* open icon.library */
  702.     FreeArgs(rda);
  703.   } /* ReadArgs */
  704.   if(ret)
  705.     PrintFault(IoErr(), 0);
  706.   return ret;
  707. }
  708.  
  709.